package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.MailBean;
import com.project.mapper.IMailMapper;
import com.project.service.IMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Arrays;

@Service
@Transactional
public class MailServiceImpl implements IMailService {
    @Autowired
    private IMailMapper mapper;
    @Override
    public void add(MailBean mail, Integer[] receiveIdArray, String[] receiveNameArray) {
        mapper.add(mail, Arrays.toString(receiveNameArray).substring(1,Arrays.toString(receiveNameArray).length()-1));
        mapper.adds(mail.getMailId(),receiveIdArray);
    }

    @Override
    public PageInfo<MailBean> findMailByItem(Integer pageNO, String title, LocalDate startDate, LocalDate endDate, Integer userId) {
        PageHelper.startPage(pageNO,2);
        PageInfo<MailBean> pg = PageInfo.of(mapper.findMailByItem(title,startDate,endDate,userId));
        return pg;
    }

    @Override
    public MailBean findMailById(Integer mailId) {
        return mapper.findMailById(mailId);
    }

    @Override
    public void delMail(Integer mailId) {
        mapper.delMail(mailId);
    }
}
